<?php
// +----------------------------------------------------------------------
// |     【ClothType】Controller 控制器
// +----------------------------------------------------------------------

declare (strict_types = 1);

namespace app\admin\controller\cloth;

use think\facade\Request;
use app\common\service\ClothType as S;
use app\common\model\ClothType as M;

class Type extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck','AdminPermission'];

	//初始化
	public function initialize(){
		parent::initialize();
		
		$this->assign('controller_title','面料分类');
	}

    // 列表
    public function index(){
        if (Request::isAjax()) {
            return $this->getJson(M::getList([['uuid','=',$this->uuid]]));
        }
        return $this->fetch();
    }

    // 添加
    public function add(){
        if (Request::isAjax()) {
			//追加uuid
			$data=array_merge(Request::post(),['uuid'=>$this->uuid]);
            return $this->getJson(S::goAdd($data));
        }
        return $this->fetch('edit',[
			'action_up'=>false,
		]);
    }

    // 编辑
    public function edit($id){
        if (Request::isAjax()) {
            $data=array_merge(Request::post(),['uuid'=>$this->uuid]);
            return $this->getJson(S::goEdit($data,['id'=>$id,'uuid'=>$this->uuid]));
        }
		
		$model=M::info(['uuid'=>$this->uuid,'id'=>$id]);
		if(!$model) $this->getJson(102);
        
		return $this->fetch('',[
			'action_up'=>true,
			'model' => $model,
		]);
    }

    // 状态
    public function status($id){
        return $this->getJson(S::goStatus(Request::post(),['id'=>$id,'uuid'=>$this->uuid]));
    }

    // 删除
    public function remove($id){
        return $this->getJson(S::goRemove(['id'=>$id,'uuid'=>$this->uuid]));
    }

    // 批量删除
    public function batchRemove(){
        return $this->getJson(S::goBatchRemove([
				['id','in',Request::post('ids')],
				['uuid','=',$this->uuid],
			]));
    }

    // 回收站
    public function recycle(){
        if (Request::isAjax()) {
            return $this->getJson(S::goRecycle([['uuid','=',$this->uuid]]));
        }
        return $this->fetch();
    }
	
    // 设置某个值
    public function setValue(){
        if (Request::isAjax()) {
            return $this->getJson(S::setFieldValue(Request::post(),['id'=>I('post.id'),'uuid'=>$this->uuid]));
        }
        return $this->fetch();
    }
}
